
<script>
	$(function(){
	$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var name = $( "#memName" ),
			allFields = $( [] ).add( name ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		
		$( "#dialog-edit" ).dialog({
			autoOpen: false,
			height: 550,
			width: 550,
			modal: true,
			buttons: {
				"确定修改": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
					bValid = bValid && checkLength( name, "username", 2, 16 );
					if ( bValid ) {
						var id=$("#memId").val();
						var username=$("#memName").val();
						var remark=$("#memRemark").val();
						var status=$("#memStatus").val();
						var time=$("#memTime").val();
						$.ajax({
							url:"update.php",
							type:"POST",
							data:"id="+id+"&name="+username+"&remark="+remark+"&status="+status+"&time="+time,
							success:function(data){
								if(data)
									{
									location.href='index.php';
									
									}
								else{
									$( ".validateTips" ).text("修改失败!"); 
									}
								$( this ).dialog( "close" );
								}
								});					
						
					}
				},
				"取            消": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$(".edit").click(function(){
			var id=$(this).attr("href");
			var memLeader=$(this).attr("rel");
			$.ajax({
				           url:"getMember.php",
				           type:"GET",
				           dataType:"json",
				           contentType: 'application/json',
				           data:"id="+id+"&name="+memLeader,
				           success:function(data)
				           {
				               $("#memId").val(data[0].id);
				               $("#memName").val(data[0].name);
				               $("#memRemark").val(data[0].remark);
				               $("#memStatus").val(data[0].status);
				               $("#memTime").val(data[0].time);
				           }
							});
			$( "#dialog-edit" ).dialog( "open" );
			return false;
			
		});
		})
</script>
<div id="dialog-edit" title="编辑小组成员">
	<fieldset>
		<input type="hidden" id="memId" /> <label>姓名</label> <input
			type="text" id="memName" class="text ui-widget-content ui-corner-all"
			autofocus="autofocus" /> <label>任务</label>
		<textarea id="memRemark" cols="43" rows='3'>见需求系统</textarea>
		<label>状态</label> <select id="memStatus">
			<option value="正常" selected='selected'>正常</option>
			<option value="忙碌">忙碌</option>
			<option value="空闲">空闲</option>
		</select> </br>
		</br> 时间: <select id="memTime" name="memTime">
			<option value="1" selected='selected'>1</option>
    <?php
				for($i = 2; $i <= 7; $i ++) {
					echo "<option value ='" . $i . "'>" . $i . "</option>";
				}
				?>
    </select>&nbsp;(天)
	</fieldset>
	<p class="validateTips">All form fields are required.</p>
</div>
